package net.zjitc.service.impl;

import net.zjitc.dao.CategoryDao;
import net.zjitc.dao.CategorySecondDao;
import net.zjitc.dao.impl.CategoryDaoImpl;
import net.zjitc.dao.impl.CategorySecondDaoImpl;
import net.zjitc.pojo.Category;
import net.zjitc.pojo.CategorySecond;
import net.zjitc.service.CategoryService;

import java.util.List;

/**
 * Created by 沈银 on 2017/11/18.
 */
public class CategoryServiceImpl implements CategoryService{
    CategoryDao dao=new CategoryDaoImpl();
    CategorySecondDao csdao=new CategorySecondDaoImpl();
    public List<Category> findAll() {
        List<Category> list=dao.findAll();
        //将找到的一级菜单与二级菜单关联
        for (Category c:list){
            List<CategorySecond> clist=csdao.findByCid(c.getCid());
            c.setSecondList(clist);
        }
        return list;
    }

    public int addCategory(String cname) {
        return dao.addCategory(cname);
    }

    public int deleteCategory(String cid) {
        return dao.deleteCategory(cid);
    }

    public Category findByCid(String cid) {
        return dao.findByCid(cid);
    }

    public int editCategory(Category category) {
        return dao.editCategory(category);
    }
}
